//
//  TimerManager.h
//  LearnCharacters
//
//  Created by HJC on 11-8-4.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <QuartzCore/QuartzCore.h>
#import "_iOSUtils_Classes.h"


#define Invalide_TimerId    0


/////////////////////////////////////
typedef struct 
{
    NSInteger       timerId;        // 定时器id
    NSInteger       tag;            // 定时器tag
    NSTimeInterval  totalTime;      // 定时器开始计算的总时间
    NSTimeInterval  stepTime;       // 跟上一次激发之后的时间间隔
} TimerStepInfo;



@class TimerManager;
@protocol TimerManagerDelegate <NSObject>
@required
- (void) timerManager:(TimerManager*)manager timerFireWithInfo:(TimerStepInfo)info;
@end



//////////////////////////////////////////
// 计时器管理, 最大不能超过每秒60帧
@interface TimerManager : NSSingleton 
{  
@private
    NSMutableArray* _timerInfos;
    NSTimer*        _timer;
}

+ (TimerManager*) shardManager;

- (NSInteger) timerIdAfterAddDelegate:(id<TimerManagerDelegate>)delegate 
                             interval:(NSTimeInterval)interval
                                  tag:(NSInteger)tag;

- (NSInteger) timerIdAfterAddDelegate:(id<TimerManagerDelegate>)delegate 
                             interval:(NSTimeInterval)interval;

- (NSInteger) timerIdAfterAddFastestTimerDelegate:(id<TimerManagerDelegate>)delegate tag:(NSInteger)tag;
- (NSInteger) timerIdAfterAddFastestTimerDelegate:(id<TimerManagerDelegate>)delegate;

- (void) fireTimerId:(NSInteger)timerId;
- (BOOL) hasTimerId:(NSInteger)timerId;

- (void) stopTimerId:(NSInteger)timerId;
- (void) stopTimerDelegate:(id<TimerManagerDelegate>)delegate onlyOne:(BOOL)onlyOne;

@end
